package com.kc.web.controller.business;

import com.kc.business.domain.BizLiteraryEnterForm;
import com.kc.business.service.IBizLiteraryEnterService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.core.redis.RedisCache;
import com.kc.common.enums.BusinessType;
import com.kc.common.utils.DictUtils;
import com.kc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/25
 */
@RestController
@RequestMapping("/business/literaryEnter")
public class BizLiteraryEnterController extends BaseController {

    @Autowired
    private IBizLiteraryEnterService literaryEnterService;
    @Resource
    private RedisCache redisCache;

    /**
     * 师承redis key
     */
    public static final String DISCIPLE_DATA = "disciple_data";

    /**
     * 获取墨客入驻列表
     */
    @PreAuthorize("@ss.hasPermi('business:literaryEnter:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLiteraryEnterForm bizShopEnterForm) {
        startPage();
        List<BizLiteraryEnterForm> list = literaryEnterService.getList(bizShopEnterForm);
        for (BizLiteraryEnterForm form : list) {
            if (StringUtils.isNotBlank(form.getLicense())) {
                //字符串转数组
                form.setLicenseImgs(StringUtils.split(form.getLicense(), ","));
            }
            if (StringUtils.isNotBlank(form.getOpus())) {
                //字符串转数组
                form.setOpusImgs(StringUtils.split(form.getOpus(), ","));
            }
            form.setIndustryLabel(DictUtils.getDictLabel("industry_type", form.getIndustry()));
            form.setTitleLabel(DictUtils.getDictLabel("title_type", form.getTitle()));
        }
        return getDataTable(list);
    }

    /**
     * 审核墨客入驻
     */
    @PreAuthorize("@ss.hasPermi('business:literaryEnter:edit')")
    @Log(title = "墨客入驻管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody @Validated BizLiteraryEnterForm bizShopEnterForm) {
        return toAjax(literaryEnterService.edit(bizShopEnterForm));
    }
}
